Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Best Way to Transition CSS Style Height from "0" to "auto"

I've seen this question and have not seen anyone provide this answer. The solution I created was perfect for my situation so I thought I'd share. Essentially, I had a page where a generated list was hidden at first by setting CSS height to "0" then expanded on click by transitioning height. However, transitions won't work with height = "auto". So I did some digging and realized that the CSS attribute "scrollHeight" will still calculate despite "height" or "max-height". So I set the "onclick" event to change the element height to the "scrollHeight".

document.getElementById('dropContent').style.height = document.getElementById('dropContent').scrollHeight + 'px';
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From the book CSS in Depth:

A value cannot transition from a length 0 to auto.

What you can do is set a height explicitly instead, the problem is that maybe you don't know what the height should be. That's only known once the contents are set and rendered in the browser, so you'll have to use JavaScript to determine the height. Unfortunately, there's no other workaround.

So you should keep using element.scrollHeight.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda